﻿using System;
using System.Reflection;

namespace NHibernate.Expression.Extensions.Utils {
    public static class MemberInfoExtensions {
        public static object GetValue(this MemberInfo m, object o) {
            if (m == null)
                throw new ArgumentNullException("m");
            if (o == null)
                throw new ArgumentNullException("o");
            if (m is PropertyInfo) {
                var p = (PropertyInfo) m;
                return p.GetValue(o, null);
            }
            if (m is FieldInfo) {
                var f = (FieldInfo) m;
                return f.GetValue(o);
            }
            throw new ArgumentException(string.Format("Invalid MemberInfo type '{0}'", m.GetType()));
        }
    }
}